<template>
  <a-modal :maskClosable="false"
    :title="title"
    :width="1024"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">

    <a-spin :spinning="confirmLoading">
      <a-form-model ref="form" v-bind="layout" :model="model" :rules="validatorRules">
        <a-tabs default-active-key="1">
          <a-tab-pane key="1" tab="店铺信息">
            <a-form-model-item label="登录帐号" v-if="!isEdit">
              <a-input placeholder="请输入登录帐号" v-model="model.loginName" />
            </a-form-model-item>
            <a-form-model-item label="登录密码" v-if="!isEdit">
              <a-input placeholder="请输入登录密码" v-model="model.pwd" />
            </a-form-model-item>
            <a-form-model-item label="店铺名称" required prop="storeName">
              <a-input placeholder="请输入店铺名称" v-model="model.storeName" />
            </a-form-model-item>
            <a-form-model-item label="联系人" required prop="adminName">
              <a-input placeholder="请输入联系人名称" v-model="model.adminName" />
            </a-form-model-item>
            <a-form-model-item label="联系手机" required prop="phone">
              <a-input placeholder="请输入联系手机" v-model="model.phone" />
            </a-form-model-item>
<!--            <a-form-model-item label="地址" required prop="address">-->
<!--              <a-input placeholder="请输入联系地址" v-model="model.address" />-->
<!--            </a-form-model-item>-->
            <a-form-model-item label="简介" required prop="remark">
              <a-textarea row="5" placeholder="请输入简介" v-model="model.remark" />
            </a-form-model-item>

            <a-form-item label="门脸图">
              <j-image-upload :isMultiple="false" v-model="model.avatar" bizPath="cert"></j-image-upload>
            </a-form-item>
          </a-tab-pane>
          <a-tab-pane key="2" tab="资质信息" force-render>
            <a-form-model-item label="营业执照(或特许证件)">
              <j-image-upload :isMultiple="false" v-model="model.businessLicense" bizPath="cert"></j-image-upload>
            </a-form-model-item>
            <a-form-model-item label="食品经营许可证(或同等证件)">
              <j-image-upload :isMultiple="false" v-model="model.foodBusinessLicense" bizPath="cert"></j-image-upload>
            </a-form-model-item>
          </a-tab-pane>
          <a-tab-pane key="3" tab="法人信息">
            <a-form-model-item label="身份证(人像面)">
              <j-image-upload :isMultiple="false" v-model="model.cardFront" bizPath="cert"></j-image-upload>
            </a-form-model-item>
            <a-form-model-item label="身份证(国微面)">
              <j-image-upload :isMultiple="false" v-model="model.cardOpposite" bizPath="cert"></j-image-upload>
            </a-form-model-item>
          </a-tab-pane>
        </a-tabs>
      </a-form-model>
    </a-spin>
  </a-modal>
</template>

<script>
import { httpAction, putAction, getAction, postAction,getFileAccessHttpUrl } from '@/api/manage'
import JImageUpload from '@/components/jeecg/JImageUpload'

export default {
  name: 'ordStoreInfoModal',
  components: {
    JImageUpload
  },
  data() {
    return {
      title: '操作',
      visible: false,
      isEdit: false,
      model: {},
      layout: {
        labelCol: { span: 6 },
        wrapperCol: { span: 12 }
      },
      confirmLoading: false,
      validatorRules: {
        storeName: [{ required: true, message: '请输入店铺名称!' }],
        workNo: [{ required: true, message: '请输入管理员工号!' }],
        adminName: [{ required: true, message: '请输入管理员名称!' }],
        phone: [{ required: true, message: '请输入手机号码!' }]
      },
      url: {
        edit: '/store/info'
      },
      fileList: []
    }
  },
  created() {
    this.modelDefault = JSON.parse(JSON.stringify(this.model))
  },
  methods: {
    add() {
      this.edit({})
      this.isEdit = false
      this.model.status = '1'
    },
    edit(record) {
      this.model = Object.assign({}, record)
      this.visible = true
      this.isEdit = true
    },
    close() {
      this.$refs.form.clearValidate()
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      const that = this
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true
          putAction(that.url.edit, that.model).then((res) => {
            if (res.success) {
              that.$message.success(res.message)
              that.$emit('ok')
              that.close()
            } else {
              that.$message.warning(res.message)
            }
          }).finally(() => {
            that.confirmLoading = false
          })
        } else {
          return false
        }
      })
    },
    handleCancel() {
      this.close()
    },
    getAvatarView: function(avatar) {
      return getFileAccessHttpUrl(avatar)
    },

  }
}
</script>

<style scoped>

</style>
